(function(){
    if (!checkConnect()) return;
    getNode("refresh").onclick = ()=>{
        //强制刷新
        publicParam.members = null;
        init();
    };
    /**
    * 初始化
    */
    async function init(){
        var rtn = await loadManbers();
        if (rtn){
            var my = getMy();
            if (!my || !my.isReal){
                alert("您还不是正式会员");
                return;
            }
            //因为所有会员信息都已经载入了，所以没必要再去区块链上查询，直接筛选出即可
            var newMembers = [];
            for(var i=0;i<publicParam.members.length;i++){
                if (!publicParam.members[i].isReal){
                    newMembers.push(publicParam.members[i]);
                }
            }
            var list = getNode("table");
            var line = list.children[0];
            clearAll(list);
            for(var i=0;i<newMembers.length;i++){
                var m = newMembers[i];
                var newLine = line.cloneNode(true);
                list.appendChild(newLine);
                var name = getSubNode(newLine,"name");
                name.innerText = m.name;
                name.tag = m.address;
                name.onclick = function(){
                    goto("member/info",this.tag);
                };
                var upname = getSubNode(newLine,"upname");
                var upmember = getMemberByAddress(m.up);
                upname.innerText = upmember.name;
                upname.tag = upmember.address;
                upname.onclick = function(){
                    goto("member/info",this.tag);
                };
                var joinTime = getSubNode(newLine,"joinTime");
                joinTime.innerText = m.joinTime;
                var count = getSubNode(newLine,"count");
                count.innerText = m.approver.length;
                var about = getSubNode(newLine,"about");
                if (m.role === undefined){
                    // 还没有获取过该用户的其他信息
                    callAPI({webapi:"getMemberData",id:m.id}, function (data){
                        m.about = data.about;
                        m.role = data.role;
                        m.skill = data.skill;
                        m.email = data.email;
                        m.wechat = data.wechat;
                        m.phone = data.phone;
                        m.awards = data.awards;
                        m.education = data.education;
                        m.experience = data.experience;
                        about.innerText = m.about;
                    });
                }else about.innerText = m.about;
            }
            setLoading(0);
        }
    }
    init();
})();